﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;

namespace Kang.WPF.ExtendMethod
{
    public static class StringToColor
    {
        public static SolidColorBrush ToSolidColorBrush(this string rgbString)
        {
            if (rgbString.StartsWith("#") != true)
            {
                throw new FormatException();
            }
            if (rgbString.Length != 7)
            {
                throw new FormatException();
            }
            byte r = Convert.ToByte(rgbString.Substring(1, 2), 16);
            byte g = Convert.ToByte(rgbString.Substring(3, 2), 16);
            byte b = Convert.ToByte(rgbString.Substring(5, 2), 16);
            return new SolidColorBrush(Color.FromRgb(r, g, b));
        }
    }
}
